{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">标题：</label>
                            <div class="layui-input-block">
                                <input type="text" {if $type==1}disabled{/if} name="c_name" lay-verify="required" placeholder="标题"  value="{$info.c_name}" class="layui-input ">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">缩略图：</label>
                            <input type="hidden" name="c_thumb" id="lay-img" lay-verify="image" value="{$info.c_thumb}">
                            <div class="layui-input-block">
                                {if $type==0}
                                <div id="lay-upload">上传图片</div>
                                {/if}
                                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                    预览图：
                                    <div class="layui-upload-list" id="lay-list">
                                        <img class="layui-append-img" src="{$info.c_thumb}" onerror="this.src='/static/admin/images/no_img.jpg'">
                                    </div>
                                </blockquote>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">状态：</label>
                            <div class="layui-input-block">
                                <input {if $type==1}disabled{/if} type="radio" name="c_status" value="1" title="上架" {if $info.c_status==1}checked{/if} />
                                <input {if $type==1}disabled{/if} type="radio" name="c_status" value="2" title="下架" {if $info.c_status==2}checked{/if} />
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">选择乐器：</label>
                            <div class="layui-input-block">
                                <select {if $type==1}disabled{/if} lay-verify="required" name="c_axe" lay-search>
                                    <option value="">请选择</option>
                                    {foreach name="axe" item="v"}
                                    <option value="{$v.axe_id}" {if $info.c_axe==$v.axe_id}selected{/if}>{$v.axe_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">选择老师：</label>
                            <div class="layui-input-block">
                                <select {if $type==1}disabled{/if} lay-verify="required" name="c_teacher" lay-search>
                                    <option value="">请选择</option>
                                    {foreach name="teachers" item="v"}
                                    <option value="{$v.user_id}" {if $info.c_teacher==$v.user_id}selected{/if}>{$v.user_username}({$v.user_phone})</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <!--xm-select-radio=""-->
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">所属琴行：</label>
                            <div class="layui-input-block">
                                <select {if $type==1 || $Think.session.groupid == 2}disabled{/if} id="l_piano" lay-verify="required" name="c_piano" xm-select="select2" xm-select-search="" xm-select-search-type="dl">
                                    <option value="">请选择</option>
                                    {foreach name="panio" item="v"}
                                    <option value="{$v.pa_id}" {if in_array($v.pa_id,$info.c_piano)}selected{/if}>{$v.pa_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md10" id="banner_content">
                            <label class="layui-form-label">内容：</label>
                            <div class="layui-input-block" id="LAY_editor" lay-verify="editor">
                                <p>{$info.c_content}</p>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">咨询人数(默认为0)：</label>
                            <div class="layui-input-block">
                                <input {if $type==1}disabled{/if} type="number" name="c_num" lay-verify="number" placeholder="咨询人数"  value="{$info.c_num}" class="layui-input ">
                            </div>
                        </div>
                        <input type="hidden" name="c_id" value="{$c_id}" />
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                {if $type==0}
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                                </button>
                                {/if}
                                <button class="layui-btn layui-btn-primary" onclick="wk.layer_close('close')">关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    var editor = wk.wang({elem:'#LAY_editor'});
    wk.uploadImg({size:5,type:'png,jpg,jpeg',url:"{:url('Upload/upload')}",domain:""});
    layui.use(['form','upload','layedit'], function() {
        var form = layui.form;
        form.verify({
            editor:function(value,item){
                if(editor.txt.html() == '<p><br></p>'){
                    return '请填写内容';
                }
            }
        });
        form.on('submit(component-form-element)', function (data) {
            data.field.c_content = editor.txt.html();
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('courseEdit')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        layer.msg(res.msg,{icon:1,time:1500,shade:0.1},function(index){
                            wk.layer_close();
                        })
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });

    });
</script>

</body>
</html>
